<!DOCTYPE html>
<html lang="en">

<head>

    <!-- Basic -->
    <meta charset="UTF-8"/>

    <title>仓管理</title>

    <!-- Mobile Metas -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>

    <!-- Favicon and touch icons -->
    <link rel="shortcut icon" href="__ADMIN__/assets/ico/favicon.ico" type="image/x-icon"/>
    <link rel="apple-touch-icon" href="__ADMIN__/assets/ico/apple-touch-icon.png"/>
    <link rel="apple-touch-icon" sizes="57x57" href="__ADMIN__/assets/ico/apple-touch-icon-57x57.png"/>
    <link rel="apple-touch-icon" sizes="72x72" href="__ADMIN__/assets/ico/apple-touch-icon-72x72.png"/>
    <link rel="apple-touch-icon" sizes="76x76" href="__ADMIN__/assets/ico/apple-touch-icon-76x76.png"/>
    <link rel="apple-touch-icon" sizes="114x114" href="__ADMIN__/assets/ico/apple-touch-icon-114x114.png"/>
    <link rel="apple-touch-icon" sizes="120x120" href="__ADMIN__/assets/ico/apple-touch-icon-120x120.png"/>
    <link rel="apple-touch-icon" sizes="144x144" href="__ADMIN__/assets/ico/apple-touch-icon-144x144.png"/>
    <link rel="apple-touch-icon" sizes="152x152" href="__ADMIN__/assets/ico/apple-touch-icon-152x152.png"/>

    <!-- start: CSS file-->

    <!-- Vendor CSS-->
    <link href="__ADMIN__/assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="__ADMIN__/assets/vendor/skycons/css/skycons.css" rel="stylesheet"/>
    <link href="__ADMIN__/assets/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>

    <!-- Plugins CSS-->
    <link href="__ADMIN__/assets/css/toastr.min.css" rel="stylesheet"/>
    <link href="__ADMIN__/assets/plugins/bootkit/css/bootkit.css" rel="stylesheet"/>
    <link href="__ADMIN__/assets/plugins/fullcalendar/css/fullcalendar.css" rel="stylesheet"/>
    <link href="__ADMIN__/assets/plugins/jquery-ui/css/jquery-ui-1.10.4.min.css" rel="stylesheet"/>

    <!-- Theme CSS -->
    <link href="__ADMIN__/assets/css/jquery.mmenu.css" rel="stylesheet"/>

    <!-- Page CSS -->
    <link href="__ADMIN__/assets/css/style.css" rel="stylesheet"/>
    <link href="__ADMIN__/assets/css/add-ons.min.css" rel="stylesheet"/>

    <!-- end: CSS file-->

    <!-- Head Libs -->
    <script src="__ADMIN__/assets/plugins/modernizr/js/modernizr.js"></script>

</head>

<body>

<!-- Start: Header -->
{include file="public/header"}
<!-- End: Header -->

<!-- Start: Content -->
<div class="container-fluid content">
    <div class="row">

        <!-- Sidebar -->
        {include file="public/sidebar"}
        <!-- End Sidebar -->

        <!-- Main Page -->
        <div class="main sidebar-minified">

            <!-- Page Header -->
            <div class="page-header">
                <div class="pull-left">
                    <ol class="breadcrumb visible-sm visible-md visible-lg">
                        <li><a href="{:url('/index')}"><i class="icon fa fa-home"></i>后台首页</a></li>
                    </ol>
                </div>
                <div class="pull-right">
                    <h2>仓列表</h2>
                </div>
            </div>
            <!-- End Page Header -->

            <!--详细信息模态框-->
            <div class="modal fade" id="detailModal" style="margin-top: 70px;" tabindex="-1" role="dialog"
                 aria-labelledby="myModalLabel">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="row">
                            <div class="col-md-12"
                                 style="float: none; display: block; margin-left: auto; margin-right: auto;">
                                <div class="panel-heading bk-bg-primary">
                                    <h6 id="detailTitle"><i class="fa fa-indent red"></i></h6>
                                </div>
                                <div class="panel-body">
                                    <form class="form-horizontal" style="text-align: center;">

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">ID</label>
                                            <div class="col-md-9">
                                                <p id="detail-id" class="form-control-static"></p>
                                            </div>
                                        </div>
                                        <hr>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">期货名称</label>
                                            <div class="col-md-9">
                                                <p id="detail-name" class="form-control-static"></p>
                                            </div>
                                        </div>
                                        <hr>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">期货名称</label>
                                            <div class="col-md-9">
                                                <p id="detail-code" class="form-control-static"></p>
                                            </div>
                                        </div>
                                        <hr>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">一个月</label>
                                            <div class="col-md-9">
                                                <p id="detail-oneMonth" class="form-control-static"></p>
                                            </div>
                                        </div>
                                        <hr>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">两个月</label>
                                            <div class="col-md-9">
                                                <p id="detail-twoMonth" class="form-control-static"></p>
                                            </div>
                                        </div>
                                        <hr>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">三个月</label>
                                            <div class="col-md-9">
                                                <p id="detail-threeMonth" class="form-control-static"></p>
                                            </div>
                                        </div>
                                        <hr>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">创建时间</label>
                                            <div class="col-md-9">
                                                <p id="detail-time" class="form-control-static"></p>
                                            </div>
                                        </div>
                                        <hr>
                                        <br>

                                    </form>
                                    <br>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--End 详细信息模态框-->

            <!--添加模态框-->
            <div class="modal fade" id="addModal" style="margin-top: 70px;" tabindex="-1" role="dialog"
                 aria-labelledby="myModalLabel">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="row">
                            <div class="col-md-12"
                                 style="float: none; display: block; margin-left: auto; margin-right: auto;">
                                <div class="panel-heading bk-bg-primary">
                                    <h6><i class="fa fa-money red"></i> 添加仓</h6>
                                </div>
                                <div class="panel-body">
                                    <form id="addForm" action="{:url('/repertory')}" method="post"
                                          class="form-horizontal">

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">期权名称</label>
                                            <div class="col-md-9">
                                                <input type="text" name="name" class="form-control" autocomplete="off">
                                                <span class="help-block"></span>
                                            </div>
                                        </div>
                                        <hr>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">期权代码</label>
                                            <div class="col-md-9">
                                                <input type="text" name="code" class="form-control" autocomplete="off">
                                                <span class="help-block"></span>
                                            </div>
                                        </div>
                                        <hr>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">一个月</label>
                                            <div class="col-md-9">
                                                <input type="text" name="oneMonth" class="form-control"
                                                       autocomplete="off">
                                                <span class="help-block"></span>
                                            </div>
                                        </div>
                                        <hr>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">两个月</label>
                                            <div class="col-md-9">
                                                <input type="text" name="twoMonth" class="form-control"
                                                       autocomplete="off">
                                                <span class="help-block"></span>
                                            </div>
                                        </div>
                                        <hr>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">三个月</label>
                                            <div class="col-md-9">
                                                <input type="text" name="threeMonth" class="form-control"
                                                       autocomplete="off">
                                                <span class="help-block"></span>
                                            </div>
                                        </div>
                                        <hr>

                                        <br>
                                        <div class="form-group" style="text-align: center;">
                                            <button type="submit" class="bk-margin-5 btn btn-default"> 确认保存</button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--End 添加模态框-->

            <!--修改模态框-->
            <div class="modal fade" id="editModal" style="margin-top: 70px;" tabindex="-1" role="dialog"
                 aria-labelledby="myModalLabel">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="row">
                            <div class="col-md-12"
                                 style="float: none; display: block; margin-left: auto; margin-right: auto;">
                                <div class="panel-heading bk-bg-primary">
                                    <h6 id="editTitle"><i class="fa fa-money red"></i></h6>
                                </div>
                                <div class="panel-body">
                                    <form id="editForm" action="" method="post" class="form-horizontal">
                                        <input type="hidden" name="_method" value="put">
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">期权名称</label>
                                            <div class="col-md-9">
                                                <input type="text" id="edit-name" name="name" class="form-control" autocomplete="off">
                                                <span class="help-block"></span>
                                            </div>
                                        </div>
                                        <hr>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">期权代码</label>
                                            <div class="col-md-9">
                                                <input type="text" id="edit-code" name="code" class="form-control" autocomplete="off">
                                                <span class="help-block"></span>
                                            </div>
                                        </div>
                                        <hr>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">一个月</label>
                                            <div class="col-md-9">
                                                <input type="text" id="edit-oneMonth" name="oneMonth" class="form-control"
                                                       autocomplete="off">
                                                <span class="help-block"></span>
                                            </div>
                                        </div>
                                        <hr>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">两个月</label>
                                            <div class="col-md-9">
                                                <input type="text" id="edit-twoMonth" name="twoMonth" class="form-control"
                                                       autocomplete="off">
                                                <span class="help-block"></span>
                                            </div>
                                        </div>
                                        <hr>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">三个月</label>
                                            <div class="col-md-9">
                                                <input type="text" id="edit-threeMonth" name="threeMonth" class="form-control"
                                                       autocomplete="off">
                                                <span class="help-block"></span>
                                            </div>
                                        </div>
                                        <hr>

                                        <br>
                                        <div class="form-group" style="text-align: center;">
                                            <button type="submit" class="bk-margin-5 btn btn-default"> 确认保存</button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--End 修改模态框-->

            <!--仓列表-->
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel">
                        <div class="panel-heading bk-bg-primary">
                            <h6><i class="fa fa-money red"></i><span class="break"></span>仓列表</h6>
                            <div class="panel-actions">
                                <a href="javascript:void(0)" data-target="#addModal" data-toggle="modal"><i
                                        class="fa fa-plus"></i></a>
                            </div>
                        </div>
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered bootstrap-datatable datatable">
                                    <thead>
                                    <tr>
                                        <th style="text-align: center">ID</th>
                                        <th style="text-align: center">期货名称</th>
                                        <th style="text-align: center">期货代码</th>
                                        <th style="text-align: center">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    {volist name="repertories" id="repertory"}
                                    <tr>
                                        <td style="text-align: center; vertical-align: middle;display: table-cell;">
                                            {$repertory.id}
                                        </td>
                                        <td style="text-align: center; vertical-align: middle;display: table-cell;">
                                            {$repertory.name}
                                        </td>
                                        <td style="text-align: center; vertical-align: middle;display: table-cell;">
                                            {$repertory.code}
                                        </td>
                                        <td style="text-align: center; vertical-align: middle;display: table-cell;">
                                            <button type="button" class="bk-margin-5 btn btn-success detail-btn"
                                                    data-target="#detailModal" data-toggle="modal"
                                                    data-id="{$repertory.id}">
                                                <i class="fa fa-search-plus"></i>
                                            </button>
                                            <button type="button" class="bk-margin-5 btn btn-info edit-btn"
                                                    data-target="#editModal" data-toggle="modal"
                                                    data-id="{$repertory.id}">
                                                <i class="fa fa-edit"></i>
                                            </button>
                                            <button type="button" class="bk-margin-5 btn btn-danger del-btn"
                                                    data-id="{$repertory.id}">
                                                <i class="fa fa-trash-o"></i>
                                            </button>
                                        </td>
                                    </tr>
                                    {/volist}
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="list-page" style="text-align: center">{:$repertories->render()}</div>
                    </div>
                </div>
            </div>
            <!--End 仓列表-->

        </div>
        <!-- End Main Page -->

    </div>
</div><!--/container-->

<div class="clearfix"></div>


<!-- start: JavaScript-->

<!-- Vendor JS-->
<script src="__ADMIN__/assets/vendor/js/jquery.min.js"></script>
<script src="__ADMIN__/assets/vendor/js/jquery-2.1.1.min.js"></script>
<script src="__ADMIN__/assets/vendor/js/jquery-migrate-1.2.1.min.js"></script>
<script src="__ADMIN__/assets/vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="__ADMIN__/assets/vendor/skycons/js/skycons.js"></script>

<!-- Plugins JS-->
<script src="__ADMIN__/assets/js/toastr.min.js"></script>
<script src="__ADMIN__/assets/plugins/jquery-ui/js/jquery-ui-1.10.4.min.js"></script>
<script src="__ADMIN__/assets/plugins/moment/js/moment.min.js"></script>
<script src="__ADMIN__/assets/plugins/fullcalendar/js/fullcalendar.min.js"></script>

<!-- Theme JS -->
<script src="__ADMIN__/assets/js/jquery.mmenu.min.js"></script>
<script src="__ADMIN__/assets/js/core.min.js"></script>

<!-- Pages JS -->
<script src="__ADMIN__/assets/js/pages/table.js"></script>

<!-- end: JavaScript-->

<script type="text/javascript">

    // 设置弹框参数
    toastr.options = {
        closeButton: true,//是否显示关闭按钮
        progressBar: true,//实现显示计时条
        timeOut: "3000",//自动关闭时间
        positionClass: "toast-top-full-width" // 顶端，宽度铺满整个屏幕
    };

    // 点击了详情按钮
    $('button.detail-btn').each(function () {
        $(this).click(function () {
            ajaxRead($(this).attr('data-id'));
        })
    });

    // 点击了编辑按钮
    $('button.edit-btn').each(function () {
        $(this).click(function () {
            ajaxEdit($(this).attr('data-id'));
        })
    });

    // 点击了删除按钮
    $('button.del-btn').each(function () {
        $(this).click(function () {

            if (confirm('你确定要 [删除] 吗?')) {
                // 删除table的tr
                var obj = $(this).parents('tr');

                ajaxDel($(this).attr('data-id'), obj);
            }

        })
    });

    // ajax获取指定需要显示的用户的信息
    function ajaxRead(id) {
        $.ajax({
            type: 'get',
            data: {'id': id},
            url: '{:url("/repertory/' + id + '")}',
            dataType: 'json',
            success: function (repertoryInfo) {
                // 显示
                $('#detail-id').html(repertoryInfo.id);
                $('#detail-name').html(repertoryInfo.name);
                $('#detail-code').html(repertoryInfo.code);
                $('#detail-oneMonth').html(repertoryInfo.oneMonth);
                $('#detail-twoMonth').html(repertoryInfo.twoMonth);
                $('#detail-threeMonth').html(repertoryInfo.threeMonth);
                $('#detail-time').html(repertoryInfo.time);
                $('#detailTitle').html('正在查看 【' + repertoryInfo.name + '】 的详细信息')
            }
        });
    }

    // ajax获取指定需要编辑的用户的信息
    function ajaxEdit(id) {
        $.ajax({
            type: 'get',
            data: {'id': id},
            url: '{:url("repertory/' + id + '/edit")}',
            dataType: 'json',
            success: function (repertoryInfo) {

                // 显示
                $('#edit-id').val(id);
                $('#edit-name').val(repertoryInfo.name);
                $('#edit-code').val(repertoryInfo.code);
                $('#edit-oneMonth').val(repertoryInfo.oneMonth);
                $('#edit-twoMonth').val(repertoryInfo.twoMonth);
                $('#edit-threeMonth').val(repertoryInfo.threeMonth);

                $('#editTitle').html('正在编辑 【' + repertoryInfo.name + '】 的信息');

                // 修改editform的action
                $('form#editForm').attr('action', '/repertory/' + id);

            }
        });
    }

    // ajax删除指定的用户
    function ajaxDel(id, obj) {
        $.ajax({
            type: 'delete',
            data: {'id': id},
            url: '{:url("/repertory/' + id + '")}',
            success: function (result) {
                console.log(result);
                if (result == 1) {
                    toastr.success('删除用户成功!');
                    obj.remove();
                    history.go(-1);
                } else {
                    toastr.error('删除用户失败!');
                }
            }
        });
    }

</script>

</body>

</html>